package com.example.listview1;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class AddStuActivity extends AppCompatActivity {
    private EditText edtName;
    private EditText edtAge;
    private RadioButton radiobtn1;
    private RadioButton radiobtn2;
    private RadioButton radiobtn3;
    private RadioButton radiobtn4;
    private RadioButton radiobtn5;
    private RadioButton radiobtn6;
    private RadioButton radiobtn7;
    private RadioButton radiobtn8;

    private Button btnAdd;

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);
        setTitle("添加学生");

        edtName= findViewById(R.id.edtName);
        edtAge= findViewById(R.id.edtAge);

        radiobtn1 = findViewById(R.id.radioBtn1);
        radiobtn2 = findViewById(R.id.radioBtn2);
        radiobtn3 = findViewById(R.id.radioBtn3);
        radiobtn4 = findViewById(R.id.radioBtn4);
        radiobtn5 = findViewById(R.id.radioBtn5);
        radiobtn6 = findViewById(R.id.radioBtn6);
        radiobtn7 = findViewById(R.id.radioBtn7);
        radiobtn8 = findViewById(R.id.radioBtn8);

        btnAdd = findViewById(R.id.btn_add);
        btnAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String name = edtName.getText().toString();
                String age  = edtAge.getText().toString();

                int imgId = R.drawable.a1;

                if(radiobtn1.isChecked()){
                    imgId = R.drawable.a1;
                }else if(radiobtn2.isChecked()){
                    imgId = R.drawable.a2;
                }else if(radiobtn3.isChecked()){
                    imgId = R.drawable.a3;
                }else if(radiobtn4.isChecked()){
                    imgId = R.drawable.a4;
                }else if(radiobtn5.isChecked()){
                    imgId = R.drawable.a5;
                }else if(radiobtn6.isChecked()){
                    imgId = R.drawable.a6;
                }else if(radiobtn7.isChecked()){
                    imgId = R.drawable.a7;
                }else if(radiobtn8.isChecked()){
                    imgId = R.drawable.a8;
                }

                Intent intent = new Intent();
                intent.putExtra("NAME",name);
                intent.putExtra("AGE",age);
                intent.putExtra("IMGID",imgId);
                setResult(2001,intent);

                finish();
            }
        });

    }

}
